package com.config;

import com.alibaba.druid.filter.stat.StatFilter;
import com.alibaba.druid.wall.WallFilter;
import com.controller.Index;
import com.controller.Redisplugin;
import com.jfinal.config.Constants;
import com.jfinal.config.Handlers;
import com.jfinal.config.Interceptors;
import com.jfinal.config.JFinalConfig;
import com.jfinal.config.Plugins;
import com.jfinal.config.Routes;
import com.jfinal.core.Const;
import com.jfinal.ext.plugin.quartz.QuartzPlugin;
import com.jfinal.kit.PropKit;
import com.jfinal.plugin.druid.DruidPlugin;
import com.jfinal.plugin.druid.DruidStatViewHandler;
import com.jfinal.plugin.ehcache.EhCachePlugin;
import com.jfinal.plugin.redis.RedisPlugin;
import com.jfinal.render.ViewType;
import com.jfinal.template.Engine;

public class Config extends JFinalConfig {
	
	public static DruidPlugin createDruidPlugin() {
		return new DruidPlugin(PropKit.get("jdbcUrl"), PropKit.get("user"), PropKit.get("password").trim());
	}
	@Override
	public void configConstant(Constants me) {
		me.setEncoding("UTF-8");
		PropKit.use("config.properties");
		me.setDevMode(PropKit.getBoolean("devMode", false));
		me.setViewType(ViewType.JSP);
		me.setMaxPostSize(2*Const.DEFAULT_MAX_POST_SIZE);

	}

	@Override
	public void configRoute(Routes me) {
		me.add("/", Index.class);
		me.add("/redisplugin", Redisplugin.class);
	}

	@Override
	public void configEngine(Engine me) {
		// TODO Auto-generated method stub

	}

	@Override
	public void configPlugin(Plugins me) {
		// 用于缓存bbs模块的redis服务(需要本地先安装有redis，并且启动状态)
	    RedisPlugin bbsRedis = new RedisPlugin("bbs", "localhost");
	    me.add(bbsRedis);
	 
//	    // 用于缓存news模块的redis服务
//	    RedisPlugin newsRedis = new RedisPlugin("news", "192.168.3.9");
//	    me.add(newsRedis);
		/**配置druid数据连接池插件**/
		DruidPlugin druidPlugin = createDruidPlugin();
		
		// 配置druid监控
		druidPlugin.addFilter(new StatFilter());
		WallFilter wall=new WallFilter();
		wall.setDbType("mysql");
		druidPlugin.addFilter(wall);
		me.add(druidPlugin);
		//配置EhCache缓存
		me.add(new EhCachePlugin());
		// quartz插件
		QuartzPlugin quartzPlugin =  new QuartzPlugin("job.properties");
		me.add(quartzPlugin);
		
	}

	@Override
	public void configInterceptor(Interceptors me) {
		// TODO Auto-generated method stub

	}

	@Override
	public void configHandler(Handlers me) {
		DruidStatViewHandler dvh = new DruidStatViewHandler("/druid");
		me.add(dvh);

	}

}
